/*! \file scheduler.c
   Implement the non-preemptive scheduler here. 
 */


if (schedule == 1) 
{
	/* This is excuted if we arrive from a blocking system call. 
	 * A blocked thread will be automatically put on the timer queue, so we should 
	 * not put it in the ready queue here.
	 */
	
	if (!thread_queue_is_empty(&ready_queue)) {
		/* Pop the head-thread off, and run it */
		int head_thread = thread_queue_dequeue(&ready_queue);
		cpu_private_data.thread_index = head_thread;
		cpu_private_data.ticks_left_of_time_slice = 20;	// Give it 20 units to run in before next context switch
	} else {
		/* Thread-queue is empty, so run the idle thread */
		cpu_private_data.thread_index = -1;				// -1 is the idle-thread
		cpu_private_data.ticks_left_of_time_slice = 1;	// Make the idle thread thin
	}
}
